package com.smag.web.controller.echarts.pie;

import com.smag.common.annotation.Log;
import com.smag.common.core.controller.BaseController;
import com.smag.common.core.domain.AjaxResult;
import com.smag.common.core.page.TableDataInfo;
import com.smag.common.enums.BusinessType;
import com.smag.common.utils.poi.ExcelUtil;
import com.smag.echarts.domain.EchartsPieEconomy;
import com.smag.echarts.service.EchartsPieEconomyService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController("pieEconomyController")
@RequestMapping("/echarts/pie/economy")
public class EconomyController extends BaseController {
    @Resource
    private EchartsPieEconomyService echartsPieEconomyService;
    @GetMapping("/listAll")
    public AjaxResult getEconomyList(){
        return echartsPieEconomyService.getEconomyList();
    }


    @PreAuthorize("@ss.hasPermi('system:economy:list')")
    @GetMapping("/list")
    public TableDataInfo list(EchartsPieEconomy echartsPieEconomy)
    {
        startPage();
        List<EchartsPieEconomy> list = echartsPieEconomyService.selectEchartsPieEconomyList(echartsPieEconomy);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('system:economy:export')")
    @Log(title = "农民经济收入来源比例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EchartsPieEconomy echartsPieEconomy)
    {
        List<EchartsPieEconomy> list = echartsPieEconomyService.selectEchartsPieEconomyList(echartsPieEconomy);
        ExcelUtil<EchartsPieEconomy> util = new ExcelUtil<>(EchartsPieEconomy.class);
        util.exportExcel(response, list, "农民经济收入来源比例数据");
    }


    @PreAuthorize("@ss.hasPermi('system:economy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(echartsPieEconomyService.selectEchartsPieEconomyById(id));
    }


    @PreAuthorize("@ss.hasPermi('system:economy:add')")
    @Log(title = "农民经济收入来源比例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EchartsPieEconomy echartsPieEconomy)
    {
        return echartsPieEconomyService.insertEchartsPieEconomy(echartsPieEconomy);
    }


    @PreAuthorize("@ss.hasPermi('system:economy:edit')")
    @Log(title = "农民经济收入来源比例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EchartsPieEconomy echartsPieEconomy)
    {
        return echartsPieEconomyService.updateEchartsPieEconomy(echartsPieEconomy);
    }


    @PreAuthorize("@ss.hasPermi('system:economy:remove')")
    @Log(title = "农民经济收入来源比例", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return echartsPieEconomyService.deleteEchartsPieEconomyByIds(ids);
    }
}
